<template>
  <div class="service-manager">
    <!-- 头部 -->
    <el-header class="header">
      <h1>
        <el-icon><Monitor /></el-icon>
        数字孪生 服务管理器
      </h1>
      <div class="header-actions">
        <el-button @click="refreshServices" :icon="Refresh" :loading="loading">
          刷新
        </el-button>
        <el-button 
          @click="quickToggleTheme" 
          :icon="currentTheme === 'light' ? Moon : Sunny"
          circle
          :title="`切换到${currentTheme === 'light' ? '深色' : '浅色'}主题`"
        />
        <el-button type="primary" @click="showSettings" :icon="Setting">
          设置
        </el-button>
      </div>
    </el-header>

    <!-- 主要内容 -->
    <el-container class="main-container">
      <!-- 服务列表 -->
      <el-main class="service-list">
        <el-card v-if="services.length === 0" class="empty-card">
          <div class="empty-content">
            <el-icon size="64" color="#dcdfe6"><Box /></el-icon>
            <p>暂无服务配置</p>
            <el-button type="primary" @click="showSettings">去设置中添加服务</el-button>
          </div>
        </el-card>

        <div v-else class="services-grid">
          <el-card 
            v-for="service in services" 
            :key="service.id" 
            class="service-card"
            :class="{ 'running': service.status === 'running' }"
          >
            <template #header>
              <div class="service-header">
                <div class="service-info">
                  <h3>{{ service.name }}</h3>
                  <el-tag 
                    :type="getStatusType(service.status)" 
                    :icon="getStatusIcon(service.status)"
                  >
                    {{ getStatusText(service.status) }}
                  </el-tag>
                </div>
                <div class="service-actions">
                  <el-button-group class="service-action-group">
                    <el-tooltip 
                      :content="service.status === 'running' ? '服务已在运行' : '启动服务'"
                      placement="top"
                      :disabled="actionLoading[service.id]?.start"
                    >
                      <el-button 
                        class="action-btn action-start"
                        type="success" 
                        size="small" 
                        :icon="VideoPlay"
                        :disabled="service.status === 'running'"
                        :loading="actionLoading[service.id]?.start"
                        @click="startService(service.id)"
                      >
                        启动
                      </el-button>
                    </el-tooltip>
                    <el-tooltip 
                      :content="service.status !== 'running' ? '服务未运行' : '停止服务'"
                      placement="top"
                      :disabled="actionLoading[service.id]?.stop"
                    >
                      <el-button 
                        class="action-btn action-stop"
                        type="danger" 
                        size="small" 
                        :icon="VideoPause"
                        :disabled="service.status !== 'running'"
                        :loading="actionLoading[service.id]?.stop"
                        @click="stopService(service.id)"
                      >
                        停止
                      </el-button>
                    </el-tooltip>
                    <el-tooltip 
                      content="重启服务"
                      placement="top"
                      :disabled="actionLoading[service.id]?.restart"
                    >
                      <el-button 
                        class="action-btn action-restart"
                        type="warning" 
                        size="small" 
                        :icon="RefreshRight"
                        :loading="actionLoading[service.id]?.restart"
                        @click="restartService(service.id)"
                      >
                        重启
                      </el-button>
                    </el-tooltip>
                  </el-button-group>
                  <el-tooltip content="更多操作" placement="top">
                    <el-dropdown @command="handleServiceAction" trigger="click">
                      <el-button size="small" :icon="More" class="more-btn" />
                      <template #dropdown>
                        <el-dropdown-menu>
                          <el-dropdown-item :command="{ action: 'logs', id: service.id }" :icon="Document">
                            查看日志
                          </el-dropdown-item>
                          <el-dropdown-item :command="{ action: 'edit', id: service.id }" :icon="Edit">
                            编辑配置
                          </el-dropdown-item>
                          <el-dropdown-item :command="{ action: 'delete', id: service.id }" :icon="Delete" divided>
                            删除服务
                          </el-dropdown-item>
                        </el-dropdown-menu>
                      </template>
                    </el-dropdown>
                  </el-tooltip>
                </div>
              </div>
            </template>

            <div class="service-content">
              <p class="service-description">{{ service.description || '无描述' }}</p>
              <div class="service-details" v-if="service.status === 'running'">
                <el-descriptions :column="2" size="small">
                  <el-descriptions-item label="进程ID">{{ service.pid }}</el-descriptions-item>
                  <el-descriptions-item label="运行时间">{{ formatRuntime(service.startTime) }}</el-descriptions-item>
                </el-descriptions>
              </div>
            </div>
          </el-card>
        </div>
      </el-main>
    </el-container>

    <!-- 日志查看对话框 -->
    <el-dialog v-model="logDialogVisible" title="服务日志" width="80%" top="5vh">
      <div class="log-container">
        <div class="log-header">
          <el-tag>{{ selectedService?.name }}</el-tag>
          <div class="log-actions">
            <el-button size="small" @click="refreshLogs" :icon="Refresh">刷新</el-button>
            <el-button size="small" @click="clearLogDisplay" :icon="Delete">清空显示</el-button>
          </div>
        </div>
        <div class="log-content" ref="logContentRef">
          <div v-if="logs.length === 0" class="no-logs">暂无日志</div>
          <div v-for="(log, index) in logs" :key="index" class="log-line" :class="getLogClass(log)">
            {{ log }}
          </div>
        </div>
      </div>
    </el-dialog>

    <!-- 设置对话框 -->
    <el-dialog 
      v-model="settingsDialogVisible" 
      title="系统设置" 
      width="90%" 
      top="3vh"
      :close-on-click-modal="false"
    >
      <Settings 
        :services="services" 
        @refresh-services="refreshServices" 
        @theme-changed="handleThemeChanged"
      />
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, onUnmounted, nextTick } from 'vue'
import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { 
  Monitor, Plus, Refresh, Box, VideoPlay, VideoPause, RefreshRight, 
  More, Document, Edit, Delete, FolderOpened, Setting, Moon, Sunny 
} from '@element-plus/icons-vue'
import { ServiceAPI } from '../services/api'
import Settings from './Settings.vue'
import { useTheme } from '../composables/useTheme'
import { getWebSocketUrl } from '../config'

// 类型定义
interface Service {
  id: string
  name: string
  status: 'running' | 'stopped' | 'error'
  pid?: number
  startTime?: Date
  description?: string
}

// 响应式数据
const services = ref<Service[]>([])
const loading = ref(false)
const actionLoading = reactive<Record<string, any>>({})
const addServiceDialogVisible = ref(false)
const logDialogVisible = ref(false)
const settingsDialogVisible = ref(false)
const selectedService = ref<Service | null>(null)
const logs = ref<string[]>([])
const editingService = ref<Service | null>(null)
const submitLoading = ref(false)

// 主题相关
const { setTheme, getTheme } = useTheme()
const currentTheme = ref('light')

// WebSocket连接
let websocket: WebSocket | null = null

const logContentRef = ref<HTMLElement>()

// 方法
const refreshServices = async () => {
  loading.value = true
  try {
    const response = await ServiceAPI.getServices()
    if (response.success) {
      services.value = response.data
    } else {
      ElMessage.error('获取服务列表失败')
    }
  } catch (error) {
    console.error('获取服务列表失败:', error)
    ElMessage.error('获取服务列表失败')
  } finally {
    loading.value = false
  }
}

const startService = async (serviceId: string) => {
  if (!actionLoading[serviceId]) {
    actionLoading[serviceId] = {}
  }
  actionLoading[serviceId].start = true
  
  try {
    const response = await ServiceAPI.startService(serviceId)
    if (response.success) {
      ElNotification.success({
        title: '启动成功',
        message: response.message
      })
      await refreshServices()
    } else {
      ElMessage.error(response.error)
    }
  } catch (error) {
    console.error('启动服务失败:', error)
    ElMessage.error('启动服务失败')
  } finally {
    actionLoading[serviceId].start = false
  }
}

const stopService = async (serviceId: string) => {
  if (!actionLoading[serviceId]) {
    actionLoading[serviceId] = {}
  }
  actionLoading[serviceId].stop = true
  
  try {
    const response = await ServiceAPI.stopService(serviceId)
    if (response.success) {
      ElNotification.success({
        title: '停止成功',
        message: response.message
      })
      await refreshServices()
    } else {
      ElMessage.error(response.error)
    }
  } catch (error) {
    console.error('停止服务失败:', error)
    ElMessage.error('停止服务失败')
  } finally {
    actionLoading[serviceId].stop = false
  }
}

const restartService = async (serviceId: string) => {
  if (!actionLoading[serviceId]) {
    actionLoading[serviceId] = {}
  }
  actionLoading[serviceId].restart = true
  
  try {
    const response = await ServiceAPI.restartService(serviceId)
    if (response.success) {
      ElNotification.success({
        title: '重启成功',
        message: response.message
      })
      await refreshServices()
    } else {
      ElMessage.error(response.error)
    }
  } catch (error) {
    console.error('重启服务失败:', error)
    ElMessage.error('重启服务失败')
  } finally {
    actionLoading[serviceId].restart = false
  }
}

const handleServiceAction = async (command: { action: string; id: string }) => {
  const { action, id } = command
  const service = services.value.find(s => s.id === id)
  
  if (!service) return
  
  switch (action) {
    case 'logs':
      selectedService.value = service
      await loadServiceLogs(id)
      logDialogVisible.value = true
      break
    case 'edit':
      // 在设置中编辑
      showSettings()
      break
    case 'delete':
      await deleteService(id)
      break
  }
}

const deleteService = async (serviceId: string) => {
  try {
    await ElMessageBox.confirm(
      '确定要删除此服务吗？此操作不可恢复。',
      '确认删除',
      {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      }
    )
    
    const response = await ServiceAPI.deleteService(serviceId)
    if (response.success) {
      ElNotification.success({
        title: '删除成功',
        message: response.message
      })
      await refreshServices()
    } else {
      ElMessage.error(response.error)
    }
  } catch (error) {
    if (error !== 'cancel') {
      console.error('删除服务失败:', error)
      ElMessage.error('删除服务失败')
    }
  }
}

const loadServiceLogs = async (serviceId: string) => {
  try {
    const response = await ServiceAPI.getServiceLogs(serviceId)
    if (response.success) {
      logs.value = response.data
      await nextTick()
      scrollToBottom()
    } else {
      ElMessage.error('获取日志失败')
    }
  } catch (error) {
    console.error('获取日志失败:', error)
    ElMessage.error('获取日志失败')
  }
}

const refreshLogs = () => {
  if (selectedService.value) {
    loadServiceLogs(selectedService.value.id)
  }
}

const clearLogDisplay = () => {
  logs.value = []
}

const scrollToBottom = () => {
  if (logContentRef.value) {
    logContentRef.value.scrollTop = logContentRef.value.scrollHeight
  }
}

// 设置相关方法
const showSettings = () => {
  settingsDialogVisible.value = true
}

const handleThemeChanged = (theme: string) => {
  setTheme(theme as any)
  currentTheme.value = theme
}

const quickToggleTheme = () => {
  const newTheme = currentTheme.value === 'light' ? 'dark' : 'light'
  handleThemeChanged(newTheme)
  ElMessage.success(`已切换到${newTheme === 'light' ? '浅色' : '深色'}主题`)
}

// 工具方法
const getStatusType = (status: string) => {
  switch (status) {
    case 'running': return 'success'
    case 'stopped': return 'info'
    case 'error': return 'danger'
    default: return 'info'
  }
}

const getStatusIcon = (status: string) => {
  switch (status) {
    case 'running': return VideoPlay
    case 'stopped': return VideoPause
    case 'error': return 'error'
    default: return 'info'
  }
}

const getStatusText = (status: string) => {
  switch (status) {
    case 'running': return '运行中'
    case 'stopped': return '已停止'
    case 'error': return '错误'
    default: return '未知'
  }
}

const formatRuntime = (startTime?: Date) => {
  if (!startTime) return '-'
  const now = new Date()
  const diff = now.getTime() - new Date(startTime).getTime()
  const minutes = Math.floor(diff / 60000)
  const hours = Math.floor(minutes / 60)
  const days = Math.floor(hours / 24)
  
  if (days > 0) return `${days}天${hours % 24}小时`
  if (hours > 0) return `${hours}小时${minutes % 60}分钟`
  return `${minutes}分钟`
}

const getLogClass = (log: string) => {
  if (log.includes('ERROR')) return 'log-error'
  if (log.includes('WARN')) return 'log-warning'
  return 'log-info'
}

// WebSocket连接
const connectWebSocket = () => {
  try {
    const wsUrl = getWebSocketUrl()
    console.log('连接WebSocket:', wsUrl)
    websocket = new WebSocket(wsUrl)
    
    websocket.onopen = () => {
      console.log('WebSocket连接已建立')
    }
    
    websocket.onmessage = (event) => {
      try {
        const data = JSON.parse(event.data)
        
        if (data.type === 'log' && selectedService.value?.id === data.serviceId) {
          logs.value.push(data.message)
          // 保持最近500条日志
          if (logs.value.length > 500) {
            logs.value.splice(0, logs.value.length - 500)
          }
          nextTick(() => scrollToBottom())
        } else if (data.type === 'status') {
          // 更新服务状态
          const index = services.value.findIndex(s => s.id === data.service.id)
          if (index !== -1) {
            services.value[index] = { ...services.value[index], ...data.service }
          }
        }
      } catch (error) {
        console.error('处理WebSocket消息失败:', error)
      }
    }
    
    websocket.onclose = () => {
      console.log('WebSocket连接已关闭')
      // 5秒后重新连接
      setTimeout(connectWebSocket, 5000)
    }
    
    websocket.onerror = (error) => {
      console.error('WebSocket连接错误:', error)
    }
  } catch (error) {
    console.error('创建WebSocket连接失败:', error)
  }
}

// 生命周期
onMounted(() => {
  refreshServices()
  connectWebSocket()
  // 初始化当前主题状态
  currentTheme.value = getTheme()
})

onUnmounted(() => {
  if (websocket) {
    websocket.close()
  }
})
</script>

<style scoped>
.service-manager {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background: #fff;
  border-bottom: 1px solid #e4e7ed;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header h1 {
  margin: 0;
  color: #303133;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 600;
}

/* 深色主题下的头部特殊样式 */
.theme-dark .header {
  background: var(--el-bg-color-overlay) !important;
  border-bottom-color: var(--el-border-color) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.theme-dark .header h1 {
  color: var(--el-text-color-primary) !important;
}

.header-actions {
  display: flex;
  gap: 12px;
}

/* 深色主题下的按钮特殊样式 */
.theme-dark .header-actions .el-button {
  background-color: var(--el-fill-color-light) !important;
  border-color: var(--el-border-color) !important;
  color: var(--el-text-color-primary) !important;
}

.theme-dark .header-actions .el-button:hover {
  background-color: var(--el-fill-color) !important;
  border-color: var(--el-border-color-dark) !important;
  color: var(--el-text-color-primary) !important;
}

.theme-dark .header-actions .el-button--primary {
  background-color: var(--el-color-primary) !important;
  border-color: var(--el-color-primary) !important;
  color: #ffffff !important;
}

.theme-dark .header-actions .el-button--primary:hover {
  background-color: var(--el-color-primary-light-3) !important;
  border-color: var(--el-color-primary-light-3) !important;
}

.main-container {
  flex: 1;
  overflow: hidden;
}

.service-list {
  padding: 20px;
  overflow-y: auto;
}

.empty-card {
  margin-top: 50px;
}

.empty-content {
  text-align: center;
  padding: 40px;
  color: #909399;
}

.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 20px;
}

.service-card {
  transition: all 0.3s;
  border: 2px solid transparent;
}

.service-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.service-card.running {
  border-color: #67c23a;
}

.service-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.service-info h3 {
  margin: 0 0 8px 0;
  color: #303133;
}

.service-actions {
  display: flex;
  gap: 8px;
}

/* 服务操作按钮组样式优化 */
.service-action-group {
  display: flex;
  gap: 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.action-btn {
  position: relative;
  font-weight: 500;
  transition: all 0.3s ease;
  min-width: 70px;
  overflow: hidden;
}

/* 按钮波纹效果 */
.action-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.action-btn:active:not(:disabled)::before {
  width: 200px;
  height: 200px;
}

/* 启动按钮 */
.action-start {
  background: linear-gradient(135deg, #67c23a 0%, #85ce61 100%) !important;
  border-color: #67c23a !important;
  color: #ffffff !important;
}

.action-start:hover:not(:disabled) {
  background: linear-gradient(135deg, #85ce61 0%, #95d475 100%) !important;
  border-color: #85ce61 !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(103, 194, 58, 0.3);
}

.action-start:active:not(:disabled) {
  transform: translateY(0);
}

.action-start.is-disabled,
.action-start:disabled {
  background: #f0f0f0 !important;
  border-color: #e0e0e0 !important;
  color: #c0c4cc !important;
  opacity: 0.6;
  cursor: not-allowed;
}

/* 停止按钮 */
.action-stop {
  background: linear-gradient(135deg, #f56c6c 0%, #f78989 100%) !important;
  border-color: #f56c6c !important;
  color: #ffffff !important;
}

.action-stop:hover:not(:disabled) {
  background: linear-gradient(135deg, #f78989 0%, #f9a3a3 100%) !important;
  border-color: #f78989 !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(245, 108, 108, 0.3);
}

.action-stop:active:not(:disabled) {
  transform: translateY(0);
}

.action-stop.is-disabled,
.action-stop:disabled {
  background: #f0f0f0 !important;
  border-color: #e0e0e0 !important;
  color: #c0c4cc !important;
  opacity: 0.6;
  cursor: not-allowed;
}

/* 重启按钮 */
.action-restart {
  background: linear-gradient(135deg, #e6a23c 0%, #ebb563 100%) !important;
  border-color: #e6a23c !important;
  color: #ffffff !important;
}

.action-restart:hover:not(:disabled) {
  background: linear-gradient(135deg, #ebb563 0%, #f0c78a 100%) !important;
  border-color: #ebb563 !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(230, 162, 60, 0.3);
}

.action-restart:active:not(:disabled) {
  transform: translateY(0);
}

.action-restart.is-disabled,
.action-restart:disabled {
  background: #f0f0f0 !important;
  border-color: #e0e0e0 !important;
  color: #c0c4cc !important;
  opacity: 0.6;
  cursor: not-allowed;
}

/* 更多按钮 */
.more-btn {
  background-color: #f5f7fa !important;
  border-color: #e4e7ed !important;
  color: #606266 !important;
  transition: all 0.3s ease;
}

.more-btn:hover {
  background-color: #ecf5ff !important;
  border-color: #b3d8ff !important;
  color: #409eff !important;
}

/* Loading 状态 */
.action-btn.is-loading {
  opacity: 0.8;
  pointer-events: none;
}

.action-btn.is-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

/* 浅色主题下的禁用状态提示 */
.action-btn.is-disabled::after,
.action-btn:disabled::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 5px,
    rgba(255, 255, 255, 0.1) 5px,
    rgba(255, 255, 255, 0.1) 10px
  );
  border-radius: 4px;
  pointer-events: none;
}

.service-content {
  margin-top: 16px;
}

.service-description {
  color: #606266;
  margin: 0 0 12px 0;
  font-size: 14px;
}

.service-details {
  margin-top: 16px;
}

/* 深色主题下的服务卡片样式 */
.theme-dark .service-card {
  background-color: var(--el-bg-color-overlay) !important;
  border-color: var(--el-border-color) !important;
}

.theme-dark .service-card.running {
  border-color: var(--el-color-success) !important;
  box-shadow: 0 0 0 1px rgba(103, 194, 58, 0.2) !important;
}

.theme-dark .service-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

.theme-dark .service-header h3 {
  color: var(--el-text-color-primary) !important;
}

.theme-dark .service-description {
  color: var(--el-text-color-secondary) !important;
}

.theme-dark .empty-content {
  color: var(--el-text-color-secondary) !important;
}

.theme-dark .empty-content p {
  color: var(--el-text-color-secondary) !important;
}

.log-container {
  height: 600px;
  display: flex;
  flex-direction: column;
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e4e7ed;
}

.log-actions {
  display: flex;
  gap: 8px;
}

.log-content {
  flex: 1;
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px;
  border-radius: 6px;
  overflow-y: auto;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.4;
}

.no-logs {
  color: #909399;
  text-align: center;
  padding: 40px;
}

.log-line {
  margin-bottom: 2px;
  word-wrap: break-word;
}

.log-error {
  color: #f56c6c;
}

.log-warning {
  color: #e6a23c;
}

.log-info {
  color: #d4d4d4;
}

/* 深色主题下的日志样式优化 */
.theme-dark .log-header {
  border-bottom-color: var(--el-border-color) !important;
}

.theme-dark .log-content {
  background: #1a1a1a !important;
  color: #e4e4e4 !important;
  border: 1px solid var(--el-border-color) !important;
}

.theme-dark .no-logs {
  color: var(--el-text-color-secondary) !important;
}

.theme-dark .log-error {
  color: #ff6b6b !important;
}

.theme-dark .log-warning {
  color: #ffd93d !important;
}

.theme-dark .log-info {
  color: #e4e4e4 !important;
}

/* 深色主题下的按钮样式优化 */
.theme-dark .service-action-group {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* 深色主题 - 启动按钮 */
.theme-dark .action-start {
  background: linear-gradient(135deg, #67c23a 0%, #5daf34 100%) !important;
  border-color: #67c23a !important;
}

.theme-dark .action-start:hover:not(:disabled) {
  background: linear-gradient(135deg, #85ce61 0%, #67c23a 100%) !important;
  box-shadow: 0 4px 12px rgba(103, 194, 58, 0.4);
}

.theme-dark .action-start.is-disabled,
.theme-dark .action-start:disabled {
  background: #2b2b2c !important;
  border-color: #3c3d3e !important;
  color: #6c6e72 !important;
  opacity: 0.5;
}

/* 深色主题 - 停止按钮 */
.theme-dark .action-stop {
  background: linear-gradient(135deg, #f56c6c 0%, #e85d5d 100%) !important;
  border-color: #f56c6c !important;
}

.theme-dark .action-stop:hover:not(:disabled) {
  background: linear-gradient(135deg, #f78989 0%, #f56c6c 100%) !important;
  box-shadow: 0 4px 12px rgba(245, 108, 108, 0.4);
}

.theme-dark .action-stop.is-disabled,
.theme-dark .action-stop:disabled {
  background: #2b2b2c !important;
  border-color: #3c3d3e !important;
  color: #6c6e72 !important;
  opacity: 0.5;
}

/* 深色主题 - 重启按钮 */
.theme-dark .action-restart {
  background: linear-gradient(135deg, #e6a23c 0%, #d99130 100%) !important;
  border-color: #e6a23c !important;
}

.theme-dark .action-restart:hover:not(:disabled) {
  background: linear-gradient(135deg, #ebb563 0%, #e6a23c 100%) !important;
  box-shadow: 0 4px 12px rgba(230, 162, 60, 0.4);
}

.theme-dark .action-restart.is-disabled,
.theme-dark .action-restart:disabled {
  background: #2b2b2c !important;
  border-color: #3c3d3e !important;
  color: #6c6e72 !important;
  opacity: 0.5;
}

/* 深色主题 - 更多按钮 */
.theme-dark .more-btn {
  background-color: var(--el-fill-color-light) !important;
  border-color: var(--el-border-color) !important;
  color: var(--el-text-color-primary) !important;
}

.theme-dark .more-btn:hover {
  background-color: var(--el-fill-color) !important;
  border-color: var(--el-color-primary) !important;
  color: var(--el-color-primary) !important;
}

/* 深色主题下的禁用按钮提示 */
.theme-dark .action-btn.is-disabled::after,
.theme-dark .action-btn:disabled::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  pointer-events: none;
}

/* 按钮图标动画 */
@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.action-restart:not(:disabled):hover .el-icon {
  animation: rotate 0.6s ease-in-out;
}

/* 按钮组响应式设计 */
@media (max-width: 768px) {
  .service-action-group {
    flex-direction: column;
    width: 100%;
  }
  
  .action-btn {
    width: 100%;
    border-radius: 4px !important;
    margin-bottom: 4px;
  }
  
  .service-actions {
    flex-direction: column;
    width: 100%;
  }
}

.dialog-footer {
  text-align: right;
}
</style>